package com.zzr.demo.redis.service.impl;

import com.zzr.demo.redis.service.MessageQueueService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.data.redis.connection.stream.ObjectRecord;
//import org.springframework.data.redis.connection.stream.RecordId;
//import org.springframework.data.redis.connection.stream.StreamRecords;
//import org.springframework.data.redis.connection.stream.StringRecord;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;
import sun.reflect.generics.reflectiveObjects.NotImplementedException;

import java.util.Collections;

/**
 * @author: xiaomi
 * @date: 2021/10/11
 * @description: 由于2.1x 版本没有实装 redis stream ,单单升级 spring-data 会有一系列的问题，于是考虑换个 服务。
 */
@Service
@Slf4j
public class MessageQueueByStreamServiceImpl implements MessageQueueService {

    final String MQ_STREAM_KEY = "mq:stream";
    @Autowired
    StringRedisTemplate stringRedisTemplate;

    /**
     * @param key
     * @param value
     * @return recordId
     */
    @Override
    public String addMessage(String key, String value) {
        throw new NotImplementedException();
//        ObjectRecord<String, String> record = StreamRecords.newRecord()
//                .in("my-stream")
//                .ofObject("my-value");

//        StringRecord stringRecord = StreamRecords.string(Collections.singletonMap(key, value)).withStreamKey(MQ_STREAM_KEY);
//        log.info("steam k:{},v:{}", key, value);
//        RecordId recordId = this.stringRedisTemplate.opsForStream().add(stringRecord);
//        log.info("add recordId:{}", recordId);
//        return recordId.getValue();
    }

    @Override
    public String getMessage(String recordId) {
        return null;
    }
}
